#if !defined COMPLEX_H
#define COMPLEX_H

#include <math.h>
#include <stdio.h>
#include <stdlib.h>


class Complex {

public:

	double real;
	double img;


	/** Constructors **/
	Complex (): real(0.0), img(0.0) {}
	Complex (double iReal): real(iReal), img(0.0) {}
	//Complex (double iReal, double iImg): real(iReal), img(iImg) {}
	Complex (double iReal, double iImg) {
		real=iReal;
		img=iImg;
	}



	/**Operator Overloading **/
	void operator+=(const Complex& c) { real += c.real; img += c.img; }
	void operator-=(const Complex& c) { real -= c.real; img -= c.img; }

	void operator*=(const Complex& c) {
		double real_tmp = (c.real * real) - (c.img * img);
		img = (c.real * img) + (c.img * real);
		real = real_tmp;
	}

	const Complex operator+(const Complex& c) {
		Complex newC (real,img);
		newC += c;
		return newC;
	}

	const Complex operator*(const Complex& c) {
		Complex newC (real,img);
		newC *= c;
		return newC;
	}

	const Complex operator-(const Complex& c) {
		Complex newC (real,img);
		newC -= c;
		return newC;
	}

	bool operator==(const Complex& c) { return real==c.real && img==c.img; }


	Complex operator- () { return Complex (-real, -img);}




	/** Util Functions **/
	double Mod () const { return sqrt ((real * real) + (img * img)); }

	void swap(Complex *c) {
		double tmp_real = real;
		double tmp_img = img;
		real = c->real;
		img = c->img;

		c->real = tmp_real;
		c->img = tmp_img;
	}

	void printValue() { printf("[%lf %lf]",real,img); }


	static void printArray(Complex *arr, int n) {

		for (int i=0; i < n; i++) {
			arr[i].printValue();
			printf("\n");
		}
	}

};

#endif

